package com.bhs.controller;

import com.bhs.pojo.User;
import com.bhs.service.UserService;
import com.bhs.vo.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    // 进行用户注册
    @PostMapping("/register")
    public ResponseData register(@RequestBody User user) {
        userService.register(user);
        return ResponseData.success();
    }

    // 根据用户名查询用户信息
    @GetMapping("/login/{username}")
    public User doSelectUserByUsername(@PathVariable("username") String username) {
        return userService.doSelectUserByUsername(username);
    }

    // 根据用户id 查询权限
    @GetMapping("/permission/{userId}")
    public List<String> doSelectUserPermissions(@PathVariable("userId") Long userId) {
        return userService.selectUserPermissions(userId);
    }
}
